package general

import (
	"github.com/shirou/gopsutil/v4/cpu"
)

// HWID = CPUID
// ID =  hash( CustomerID + HWID)
type GeneralDevice struct {
	ID string
}

func (d *GeneralDevice) GetID() (string, error) {

	// 获取详细的 CPU 信息
	info, err := cpu.Info()
	if err != nil {
		return "", err
	}

	//第一个cpu的信息
	fcpu := info[0]

	if len(fcpu.PhysicalID) > 4 {
		return fcpu.PhysicalID, nil
	} else {
		return fcpu.String(), nil //linux 下没有PhysicalID, 整个cpu[0]信息
	}

}

func (d *GeneralDevice) GetCpuInfo() (cpus []string, err error) {

	// 获取详细的 CPU 信息
	info, err := cpu.Info()
	if err != nil {
		return nil, err
	}

	for _, fcpu := range info {
		cpus = append(cpus, fcpu.String())
	}

	return cpus, nil
}
